package com.hospital.xiaochengxiu.wu.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hospital.xiaochengxiu.wu.entity.CardLogin;
import com.hospital.xiaochengxiu.wu.entity.CardName;
import com.hospital.xiaochengxiu.wu.service.CardLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/CardLogin")
public class CardLoginController {
    @Autowired
    private CardLoginService cardLoginService;

    @PostMapping("/login")
    public String CardLogin(@RequestBody JSONObject req){
        System.out.println("123133");
        String name = req.getString("name");
        String idCard = req.getString("idCard");
        String password = req.getString("password");
        String sex = req.getString("sex");
        String phone = req.getString("phone");
        Integer age = req.getInteger("age");
        CardLogin card=new CardLogin(password,idCard,name,sex,phone,age);
        boolean b = cardLoginService.InsCard(card);
        return JSON.toJSONString(b);
    }

    @PostMapping("/FindName")
    public String FindName(@RequestBody JSONObject req){
        String phone = req.getString("phone");

        CardName cardName = cardLoginService.FindName(phone);
        return JSON.toJSONString(cardName);
    }

    @PostMapping("/FindNameIdCard")
    public String FindNameIdCard(@RequestBody JSONObject req){
        String name = req.getString("name");
        String idCard = req.getString("idCard");

        CardName cardName = cardLoginService.FindNameCard(name, idCard);
        if (cardName!=null){
            return JSON.toJSONString(cardName);
        }else {
            return JSON.toJSONString(null);
        }
    }

}
